<script setup>
import { ref, defineProps } from 'vue';
import { showToast } from 'vant';
import useUserStore from '@/store/user';
import { useRoute } from 'vue-router';

const props = defineProps({
    password1: String,
    email: String
})


const userStore = useUserStore()

let username = ref('')
let password = ref('')

const types = useRoute().params.types

const onsubmit = () => {
    if (username.value == "" || password.value == "" || props.password1 == "") {
        showToast('注册失败！信息未完善');
    }
    else if (props.password1 !== undefined && password.value != props.password1) {
        showToast('密码输入两次不一致！');
    }
    else {
        userStore.userRegister(username.value, password.value, types, props.email)
    }
}
</script>

<template>
    <van-cell-group style="margin-top: 5px;">
        <van-field v-model="username" required label="用户名" type="text" placeholder="用户名注册后不可修改" />

        <van-field v-model="password" required type="password" label="密码" placeholder="请输入密码" />
        <slot></slot>

        <!-- 登录按钮 -->
        <div style="margin: 16px">
            <van-button round block type="info" native-type="submit" @click="onsubmit">注册</van-button>
        </div>
    </van-cell-group>
</template>

<style scoped></style>